package com.zz.yt.lib.bluetooth.delegate.print.mht;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ToastUtils;
import com.whf.android.jar.util.log.LatteLogger;
import com.whf.android.jar.util.storage.LattePreference;
import com.zz.yt.lib.bluetooth.R;
import com.zz.yt.lib.bluetooth.base.Bluetooth;
import com.zz.yt.lib.bluetooth.delegate.print.mht.modle.PrintMhtManager;
import com.zz.yt.lib.ui.CustomTitleBar;


/**
 * 美恒通蓝牙打印
 *
 * @author qf
 * @version 1.0
 **/
public class PrintMhtDelegate extends BaseBluetoothMhtDelegate {


    @NonNull
    public static PrintMhtDelegate create() {
        Bundle args = new Bundle();
        PrintMhtDelegate fragment = new PrintMhtDelegate();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void setCustomTitleBar(@NonNull CustomTitleBar titleBar) {
        titleBar.setText("美恒通蓝牙打印");
    }

    @Override
    protected Object setLayout() {
        return R.layout.blu_delegate_added_print;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        super.onBindView(savedInstanceState, rootView);


        rootView.findViewById(R.id.layout_bt_un).setOnClickListener(v -> onReplace());
        rootView.findViewById(R.id.id_text_replace).setOnClickListener(v -> onReplace());
        rootView.findViewById(R.id.id_btn_print_start).setOnClickListener(v -> startPrint());

    }

    /**
     * 是否连接
     */
    protected void inMac() {
        super.inMac();
        RelativeLayout layoutBtOn = mRootView.findViewById(R.id.layout_bt_on);
        LinearLayout layoutBtUn = mRootView.findViewById(R.id.layout_bt_un);
        /*
         * 显示连接设备
         */
        TextView mTextBtEquipment = mRootView.findViewById(R.id.id_text_bt_equipment);
        if (TextUtils.isEmpty(mac)) {
            //一次都没连接过
            layoutBtOn.setVisibility(View.GONE);
            layoutBtUn.setVisibility(View.VISIBLE);
        } else {
            LatteLogger.i(mac);
            //
            layoutBtOn.setVisibility(View.VISIBLE);
            layoutBtUn.setVisibility(View.GONE);
            //显示连接的蓝牙名称
            final String device = LattePreference.getCustomAppProfile(Bluetooth.BLUETOOTH);
            mTextBtEquipment.setText(device);
        }
    }

    protected void startPrint() {
        if (!isPrint) {
            ToastUtils.showShort("请连接蓝牙");
            return;
        }
        PrintMhtManager.getInstance(mPrinter).printf_80();
    }

//    private void startPrint() {
//        if (!isPrint) {
//            ToastUtils.showShort("请连接蓝牙");
//            return;
//        }
//        PrintUtils.printBarCode(mPrinter);

//    }

}
